﻿import QtQuick 2.12
import QtQuick.Controls 2.12

Button {
    id:controlRoot

    property color  iconCheckedColor:"green"
    property color  iconUncheckedColor:"red"
    property color  iconHoverdColor:iconCheckedColor

    property url    iconCheckedSource:""
    property url    iconUncheckedSource:""

    property color  bgNormalColor:"transparent"
    property color  bgHoverdColor:"transparent"

    property real   __opacity:1

    display: Button.IconOnly
    width: 50
    height: width
    checkable: true
    hoverEnabled: true
    icon.source:controlRoot.checked?iconCheckedSource:iconUncheckedSource
    icon.width: Math.min(controlRoot.width,controlRoot.height)
    icon.height: Math.min(controlRoot.width,controlRoot.height)
    icon.color:controlRoot.checked?iconCheckedColor:(controlRoot.hovered?iconHoverdColor:iconUncheckedColor)
    opacity: controlRoot.enabled?__opacity:0.6
    onPressed: __opacity = 0.5
    onReleased: __opacity = 1

    background: Rectangle{
        color: controlRoot.hovered?bgHoverdColor:bgNormalColor
    }
}
